package com.itheima.mapper;

import com.itheima.pojo.Goods;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Name GoodsMapper
 * @Author BaiXin
 * @Date 2022-10-19 20:35
 */

public interface GoodsMapper {
    /**
     * 查询所有
     * @return
     */
    @Select("select * from goods")
    List<Goods> selectAll();

    /**
     * 根据id删除
     * @param id
     */
    @Delete("delete from goods where id = #{id}")
    void deleteById(Integer id);

    /**
     * 更新
     * @param goods
     */
    @Update("update goods set id = #{id},name = #{name},price =#{price}," +
            "costprice = #{costprice},surplusnum=#{surplusnum},allnum = #{allnum}," +
            "created = #{created}  where id = #{id}")
    void update(Goods goods);

    /**
     * 添加
     * @param goods
     */
    @Insert("insert into goods (name,price,costprice,surplusnum,allnum,created) " +
            "values (#{name},#{price},#{costprice},#{surplusnum},#{allnum},#{created})")
    void add(Goods goods);
}
